import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';

class HeroStart extends StatefulWidget {
  @override
  _HeroStartState createState() => _HeroStartState();
}

class _HeroStartState extends State<HeroStart> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: HeroAnimation(),
    );
  }
}


class PhotoHero extends StatelessWidget {
  const PhotoHero({Key key, this.value, this.onTap, this.width})
      : super(key: key);
  final String value;
  final VoidCallback onTap;
  final double width;

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      width: width,
      child: Hero(
          tag: value,
          child: Material(
            color: Colors.transparent,
            child: InkWell(
              onTap: onTap,
              child: Image.network(
                value,
                fit: BoxFit.contain,
              ),
            ),
          )),
    );
  }
}

class HeroAnimation extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
//    timeDilation = 2.0;
    return Scaffold(
      appBar: AppBar(
        title: Text("Hero One"),
      ),
      body: Center(
        child: PhotoHero(
          value:
              "http://b-ssl.duitang.com/uploads/item/201504/19/20150419H5539_KABWt.jpeg",
          width: 400,
          onTap: () {
            Navigator.of(context)
                .push(MaterialPageRoute<void>(builder: (BuildContext context) {
              return Scaffold(
                appBar:  AppBar(
                  title: Text('Hero Two'),
                ),
                body: Container(
                  color: Colors.amberAccent,
                   padding: EdgeInsets.all(20),
                  alignment: Alignment.topCenter,
                  child: PhotoHero(
                    value: 'http://b-ssl.duitang.com/uploads/item/201504/19/20150419H5539_KABWt.jpeg',
                    width: 50,
                    onTap: (){
                      Navigator.pop(context);
                    },
                  ),
                ),
              );
            }));
          },
        ),
      ),
    );
  }
}
